package leetcode_2501_2600;

import java.util.Arrays;

public class LeeCode_2594 {
    public static void main(String[] args) {

    }
    private static long repairCars(int[] ranks, int cars) {
        int minR = ranks[0];
        for (int rank : ranks) {
            minR = Math.min(minR, rank);
        }
        long left = 0, right = (long) minR * cars * cars;
        while (left + 1 < right){
            long mid = (left + right) / 2, s = 0;
            for (int rank : ranks) {
                s += Math.sqrt(mid / rank);
            }
            if (s >= cars){
                right = mid;
            }else {
                left = mid;
            }
        }
        return right;
    }
}
